package com.cxg.fairy.ec.main.index;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.SimpleClickListener;
import com.cxg.fairy.delegates.LatteDelegate;
import com.cxg.fairy.ec.detail.IGoodsDetailDelegate;
import com.cxg.fairy.ec.main.index.ad.ADGoodsHtmlDelegate;
import com.cxg.fairy.ec.main.index.ad.ADGoodsListDelegate;
import com.cxg.fairy.ec.main.index.ad.RushBuyListDelegate;
import com.cxg.fairy.ec.main.personal.favor.FavorDelegate;
import com.cxg.fairy.ec.main.personal.order.OrderListEntryDelegate;
import com.cxg.fairy.ec.main.search.SearchListDelegate;
import com.cxg.fairy.ec.pay.DepositDelegate;
import com.cxg.fairy.ui.recycler.MultipleFields;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;
import com.cxg.fairy.util.log.LatteLogger;
/**
 * Created by CFairy
 */

public class IndexItemClickListener extends SimpleClickListener {

    private final LatteDelegate DELEGATE;

    private IndexItemClickListener(LatteDelegate delegate) {
        this.DELEGATE = delegate;
    }

    public static SimpleClickListener create(LatteDelegate delegate) {
        return new IndexItemClickListener(delegate);
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        final MultipleItemEntity entity = (MultipleItemEntity) baseQuickAdapter.getData().get(position);
        final int goodsId = entity.getField(MultipleFields.ID);
        final String itemType = entity.getField(MultipleFields.ITEMTYPE);
        final String JumpValue = entity.getField(MultipleFields.JUMP_VALUE);
        final int indexImgIdA = entity.getField(MultipleFields.INDEX_IMG_A_ID);
        LatteDelegate delegate = null;
        switch (itemType){
            case "NAVIBUTTON":
                if ("deposit".equals(JumpValue)){
                    delegate = DepositDelegate.create("account");
                } else if ("favor_list".equals(JumpValue)) {
                    final FavorDelegate favorDelegate = new FavorDelegate();
                    delegate = favorDelegate;
                } else if ("my_orders".equals(JumpValue)) {
                    delegate = OrderListEntryDelegate.create("ALL");
                } else {
                    delegate = SearchListDelegate.create(JumpValue);
                }
                DELEGATE.getSupportDelegate().start(delegate);
                break;
            //限时抢购
            case "SNAPGOODS":
                delegate = RushBuyListDelegate.create(0);
                DELEGATE.getSupportDelegate().start(delegate);
                break;
            case "HEADERADBANNER":
                delegate = ADGoodsHtmlDelegate.create(goodsId);
                DELEGATE.getSupportDelegate().start(delegate);
                break;
            case "INDEXGOODS":
                delegate = IGoodsDetailDelegate.create(goodsId);
                DELEGATE.getSupportDelegate().start(delegate);
                break;
            case "INDEXIMG":
                delegate = ADGoodsListDelegate.create(goodsId);
                DELEGATE.getSupportDelegate().start(delegate);
                break;
            case "INDEXIMGS":
//                delegate = ADGoodsListDelegate.create(indexImgIdA);
            default:
                break;
        }

    }

    @Override
    public void onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
    }

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
    }

    @Override
    public void onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
    }
}
